/*
 * Copyright (c) 2010 Andy Aspell-Clark
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
package uk.org.aspellclark.agenedb.gedcom.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Multimedia extends GedcomRecord {

	public static String FIELD_NAME_filename = "filename";
	public static String FIELD_NAME_format = "format";

	public String filename;
	public String format;
	public String title;
	public String fileReference;
	public String recIdNumber;
	public String changeDateId;
	public String continuedObjectId;
	public ChangeDate changeDate = new ChangeDate();
	public Multimedia continuedObject = new Multimedia();

	public List<Note> notes = new ArrayList<Note>();
	public List<Citation> citations = new ArrayList<Citation>();
	public List<String> blob = new ArrayList<String>();
	public List<UserReference> userReferences = new ArrayList<UserReference>();

	public static String DB_TABLE_NAME = "multimedia";

	/**
	 * Default Constructor.
	 */
	public Multimedia() {
	}

	/**
	 * Constructor used for creating an Animal from a Database Row. 
	 * @param arow
	 */
	public Multimedia(HashMap<String, String> arow) {
		this.filename = arow.get(FIELD_NAME_filename);
		this.format = arow.get(FIELD_NAME_format);
	}

	@Override
	public HashMap<Integer, ArrayList<String>> getFields() {
		HashMap<Integer, ArrayList<String>> fields = new HashMap<Integer, ArrayList<String>>();

		int x = 1;
		fields.put(x++, this.getArrayList(FIELD_NAME_UNIQUE_IDENTIFIER, "INTEGER PRIMARY KEY"));
		fields.put(x++, this.getArrayList(FIELD_NAME_filename, "VARCHAR(155)"));
		fields.put(x++, this.getArrayList(FIELD_NAME_format, "VARCHAR(55)"));

		return fields;
	}

	@Override
	public String getSqlInsert() {
		StringBuilder sqlStmt = new StringBuilder(super.getSqlInsert());
		sqlStmt.append("\"").append(this.filename).append("\"");
		sqlStmt.append(",\"").append(this.format).append("\"");

		sqlStmt.append(");");
		return sqlStmt.toString();
	}

	/**
	 * return the sql code to update a computer in the database.
	 */
	@Override
	public String getSqlUpdate() {
		StringBuilder sqlStmt = new StringBuilder(super.getSqlUpdate());
		sqlStmt.append(" ").append(FIELD_NAME_filename).append("=\"").append(this.filename).append("\"");
		sqlStmt.append(",").append(FIELD_NAME_format).append("=\"").append(this.format).append("\"");

		sqlStmt.append(" where ").append(FIELD_NAME_UNIQUE_IDENTIFIER).append("=").append(this.uniqueIdentifier);
		return sqlStmt.toString();
	}

	@Override
	public String getTableName() {
		return DB_TABLE_NAME;
	}
}
